
package com.sskj.jkzx.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.sskj.jkzx.domain.entity.EngQueryParam;
import com.sskj.jkzx.domain.entity.eng.EngLxpwInfo;
import com.sskj.jkzx.domain.entity.eng.EngProjectInfo;
import com.sskj.jkzx.domain.entity.eng.EngZjlyInfo;
import com.sskj.utils.HttpHelp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping(value = "**/sskj/project")
@Api(value = "项目信息查询", description = "项目信息查询")
public class ProjectInfoServiceImpl {

	protected final Log logger = LogFactory.getLog(ProjectInfoServiceImpl.class);

	@Value("${sskj.cmisServer}")
	private String cmisServer;

	/***
	 * 项目信息
	 * 
	 * @return
	 */
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/xm", method = RequestMethod.GET)
	@ApiOperation(value = "项目信息查询", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(name = "xmId", value = "项目ID", paramType = "form", dataType = "string") })
	public List<EngProjectInfo> queryEngXmInfo(@ApiIgnore EngQueryParam engQueryParam) {

		List<EngProjectInfo> results = new ArrayList<EngProjectInfo>();

		try {
			String xms = HttpHelp.sendGet(cmisServer + "/seam/resource/v1/jkzx/eng/xminfo/" + engQueryParam.getXmId(),
					null);

			if (xms != null) {
				results.addAll(JSON.parseArray(xms, EngProjectInfo.class));
			}
		} catch (Exception e) {
			logger.info(e.getMessage());
		}

		logger.info(JSONArray.toJSONString(results));

		return results;
	}

	/***
	 * 项目资金来源信息查询
	 * 
	 * @return
	 */
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/xmzjly", method = RequestMethod.GET)
	@ApiOperation(value = "项目资金来源信息查询", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(name = "xmId", value = "项目ID", paramType = "form", dataType = "string") })
	public List<EngZjlyInfo> queryEngZjlyInfo(@ApiIgnore EngQueryParam engQueryParam) {

		List<EngZjlyInfo> results = new ArrayList<EngZjlyInfo>();

		try {
			String xms = HttpHelp
					.sendGet(cmisServer + "/seam/resource/v1/jkzx/eng/xmzljlinfo/" + engQueryParam.getXmId(), null);

			if (xms != null) {
				results.addAll(JSON.parseArray(xms, EngZjlyInfo.class));
			}
		} catch (Exception e) {
			logger.info(e.getMessage());
		}

		logger.info(JSONArray.toJSONString(results));

		return results;
	}

	/***
	 * 立项批文信息查询
	 * 
	 * @return
	 */
	@CrossOrigin(origins = "*", maxAge = 3600)
	@RequestMapping(value = "/lxpw", method = RequestMethod.GET)
	@ApiOperation(value = "立项批文查询", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(name = "xmId", value = "项目ID", paramType = "form", dataType = "string") })
	public List<EngLxpwInfo> queryEngLxpwInfos(@ApiIgnore EngQueryParam engQueryParam) {

		List<EngLxpwInfo> results = new ArrayList<EngLxpwInfo>();

		try {
			String xms = HttpHelp
					.sendGet(cmisServer + "/seam/resource/v1/jkzx/eng/xmlxpwinfo/" + engQueryParam.getXmId(), null);

			if (xms != null) {
				results.addAll(JSON.parseArray(xms, EngLxpwInfo.class));
			}
		} catch (Exception e) {
			logger.info(e.getMessage());
		}

		logger.info(JSONArray.toJSONString(results));

		return results;
	}
}
